#include "AI.h"
#include "TaskPerformer.h"

mtBEGIN(AI)
	mtBASE(ECS::Component);
	mtMETHOD(onStart);
mtEND


AI::AI() :
	_cachedTaskPerformer(nullptr)
{

}

AI::~AI()
{
	
}

void AI::onStart()
{
	_cachedTaskPerformer = getComponent<TaskPerformer>();
}

void AI::addPackage( ai::AIPackage* package )
{
	_packages.push_back(package);
}

void AI::selectTask()
{
	assert(_cachedTaskPerformer);

	if (_cachedTaskPerformer->hasTask())
		return;

	size_t i = 0;
	float decisionDone = false;
	while (i < _packages.size() && !decisionDone)
	{
		auto package = _packages.at(i);
		auto task = package->createTask();
		if (task != nullptr)
		{
			decisionDone = true;
			_cachedTaskPerformer->addTask(task);
		}
	}
}

